@model Senparc.Scf.AreaBase.Admin.IAdminPageModelBase
@using Senparc.Scf.XscfBase;
@using Senparc.Scf.Core.Areas;
@using Microsoft.AspNetCore.Http;
@inject Senparc.Scf.Service.SysMenuService _sysMenuService
@inject IHttpContextAccessor _httpContextAccessor
@addTagHelper *, Senparc.Areas.Admin
@{
    var sysMenuDtos = await _sysMenuService.GetMenuTreeDtoByCacheAsync();
}

@functions{
    /// <summary>
    /// 判断当前页面是否为 XSCF 模块入口
    /// </summary>
    /// <param name="currentMenuUrl"></param>
    /// <returns></returns>
    string CurrentXscfPage(string currentMenuUrl)
    {
        if (!Model.Uid.IsNullOrEmpty())
        {
            var pathAndQuery = Microsoft.AspNetCore.Http.Extensions.UriHelper.GetEncodedPathAndQuery(_httpContextAccessor.HttpContext.Request);
            if (pathAndQuery.Contains("/Admin/XscfModule/Start", StringComparison.OrdinalIgnoreCase) &&
                currentMenuUrl.Contains(Model.Uid, StringComparison.OrdinalIgnoreCase))
            {
                return "current-page-xscf";
            }
            return "";
        }

        return "";
    }
    /// <summary>
    /// 判断当前页面是否为 XSCF 子页面
    /// </summary>
    /// <param name="currentMenuUrl"></param>
    /// <returns></returns>
    string CurrentXscfSubPage(string currentMenuUrl)
    {
        var pathAndQuery = Microsoft.AspNetCore.Http.Extensions.UriHelper.GetEncodedPathAndQuery(_httpContextAccessor.HttpContext.Request);
        if (pathAndQuery.Contains(currentMenuUrl, StringComparison.OrdinalIgnoreCase) ||
            (ViewData["TempMenuUrl"] is string tempMenuUrl && currentMenuUrl.Contains(tempMenuUrl, StringComparison.OrdinalIgnoreCase)))
        {
            return "current-page-xscf";
        }
        return "";
    }

}
<div class="col-md-3 left_col">
    <div class="left_col scroll-view">
        <div class="navbar nav_title hidden-small">
            @*<a href="/Home/Index" class="site_title">
                    <img src="~/images/Admin/base/head/logo_230x55.png" class="hidden-small" />
                    <img src="~/images/Admin/base/head/logo_70x55.png" class="hidden-lg" />
                </a>*@
            <a href="index.html" class="site_title">
                <img src="~/images/Admin/base/head/logo_230x55.png" />
            </a>
        </div>

        <div class="clearfix"></div>
        <!-- menu profile quick info -->
        <div class="profile clearfix">
            <div class="profile_pic">
                <img src="~/images/Admin/base/head/logo_128x128.png" class="img-circle profile_img" style="background-color:transparent" />
            </div>
            <div class="profile_info" style="padding: 25px 0px 10px;">
                <span>Welcome,</span>
                <h2>@Model.UserName</h2>
            </div>
        </div>
        <!-- /menu profile quick info -->
        <!-- sidebar menu -->
        <div id="sidebar-menu" class="main_menu_side hidden-print main_menu">
            <div class="menu_section">
                @*<h3>菜单</h3>*@
                <ul class="nav side-menu">
                    <li>
                        <a href="~/Admin/Index">首页</a>
                    </li>
                    @foreach (var item in sysMenuDtos)
                    {
                        <li>
                            <a href="@item.Url">
                                @if (!string.IsNullOrEmpty(item.Icon))
                                {
                                    <i class="@item.Icon"></i>
                                }
                                @item.MenuName

                            </a>
                            @if (item.Children != null)
                            {
                                <ul class="nav child_menu">
                                    @foreach (var childrenItem in item.Children.Where(_ => _.IsMenu))
                                    {
                                        <li>
                                            @{
                                                var xscfRegister = Model.XscfRegisterList.FirstOrDefault(z => !childrenItem.Url.IsNullOrEmpty() && childrenItem.Url.Contains($"uid={z.Uid}", StringComparison.OrdinalIgnoreCase));
                                            }
                                            @if (xscfRegister != null)
                                            {
                                                if (xscfRegister is Senparc.Scf.Core.Areas.IAreaRegister xscfAreapage &&
                                                xscfAreapage.AareaPageMenuItems.Count() > 0)
                                                {
                                                    //这是一个 XSCF UI 模块菜单，并且包含多个菜单配置
                                                    <a><i class="@childrenItem.Icon"></i> @childrenItem.MenuName<span class="fa fa-chevron-down"></span></a>
                                                    <ul class="nav child_menu">
                                                        <li class="sub_menu xscf_area_submenu">
                                                            <a href="@childrenItem.Url" class="@CurrentXscfPage(childrenItem.Url)">
                                                                <i class="fa fa-gear"></i>
                                                                <text>设置/执行</text>
                                                            </a>
                                                        </li>
                                                        @foreach (var xscfSubMenu in xscfAreapage.AareaPageMenuItems)
                                                        {
                                                            <li class="xscf_area_submenu">
                                                                <a href="@xscfSubMenu.Url" class="@CurrentXscfSubPage(xscfSubMenu.Url)">
                                                                    @if (!string.IsNullOrEmpty(xscfSubMenu.Icon))
                                                                    {
                                                                        <i class="@xscfSubMenu.Icon"></i>
                                                                    }
                                                                    @xscfSubMenu.Name
                                                                </a>
                                                            </li>
                                                        }
                                                    </ul>
                                                }
                                                else
                                                {
                                                    //这是一个普通的 XSCF（可能只包含 Functions）菜单
                                                    <a href="@childrenItem.Url" class="@CurrentXscfPage(childrenItem.Url)">
                                                        @if (!string.IsNullOrEmpty(childrenItem.Icon))
                                                        {
                                                            <i class="@childrenItem.Icon"></i>
                                                        }
                                                        @childrenItem.MenuName
                                                    </a>
                                                }
                                            }
                                            else
                                            {
                                                //其他菜单，如系统或自定义菜单
                                                <a href="@childrenItem.Url">
                                                    @if (!string.IsNullOrEmpty(childrenItem.Icon))
                                                    {
                                                        <i class="@childrenItem.Icon"></i>
                                                    }
                                                    @childrenItem.MenuName
                                                </a>
                                            }
                                        </li>
                                    }
                                </ul>
                            }
                        </li>
                    }
                </ul>
            </div>
        </div>
        <!-- /sidebar menu -->
    </div>
</div>
<!-- /menu footer buttons -->
